
public class TwoStacks {
	private Object[] stackStorage;
	int firstStack;
	int secondStack;
	
	TwoStacks(int i){
		stackStorage = new Object[i];
		firstStack = 0;
		secondStack = i-1;
	//	System.out.println(firstStack +" "+ secondStack + " "+ stackStorage.length);
	}
	
	public void pushOne(Object e) throws Exception{
//		if (stackStorage[firstStack] != null)
//			throw new Exception("Belegt 1");
		stackStorage[firstStack] = e;
		firstStack++;
		if (check())
			throw new StackColissionException("FIRST Stack Touched SECOND Stack"); 
	}
	public void pushTow(Object e) throws Exception{
// 		if (stackStorage[secondStack] != null)
//			throw new Exception("Belegt 2");
		stackStorage[secondStack] = e;
		secondStack--;
		if (check())
			throw new StackColissionException("SECOND Stack Touched FIRST Stack"); 
	}
	
	public Object popOne() throws Exception{
		Object help;
		if (firstStack > 0){
			firstStack--;
			help = stackStorage[firstStack];
			stackStorage[firstStack] = null;
			return help;
		}
		return null;
	}
	
	public Object popTwo() throws Exception{
		Object help;
		if (secondStack < stackStorage.length-1){
			secondStack++;
			help = stackStorage[secondStack];
			stackStorage[secondStack] = null;
			return help;
		}
		return null;
	}
	private boolean check(){
		return (firstStack >= secondStack);
	}
}
